package com.huaxin.hxmodulesystem.common;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Random;

@Component
public class VerificationCodeGenerator {

    private final int CODE_LENGTH = 6; // 验证码长度

    /**
     * 生成指定长度的随机数字验证码
     *
     * @return 返回生成的验证码字符串
     */
    public String generateCode() {
        Random random = new Random();
        StringBuilder code = new StringBuilder(CODE_LENGTH);
        for (int i = 0; i < CODE_LENGTH; i++) {
            int digit = random.nextInt(10); // 生成0-9之间的随机数
            code.append(digit);
        }
        return code.toString();
    }
}